import Vue from 'vue'
import Router from 'vue-router'
import lazyRouter from '../libs/lazyRouter'
import { getRoutes } from '../libs/createRouter'
import routerArr from './routers'
import { checkResourceEnter,checkToken } from "@/api/acceptantce"
Vue.use(Router)

/* Layout */
import Layout from '@/layout'
import PageContent from '@/layout/pageContent.vue'
import { getServConfirmParam } from '@/api/settlement'
import { setToken10 } from '@/utils/auth'

/**
 * Note: sub-menu only appear when route children.length >= 1
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/*
  这里的 routes 是项目中不需要动态创建的组件，也就是任意权限都可访问的组件
  一般情况下都包含 登录组件、404 组件、首页等
  要注意至少包含登录组件，因为动态创建路由的先行条件是，用户登录后根据其权限，获取路由列表，从而动态创建
 */

const constantRoutes = [
    {
        path: '/404',
        component: '404',
        hidden: true
    },
    {
        path: '/demo',
        redirect: '/demo',
        component: Layout,
        meta: { title: '测试页面' },
        children: [
            {
                path: '/',
                name: 'demo',
                component: (resolve) => require(['@/views/demo/demo'], resolve),
                meta: { title: 'demo' }
            }
        ]
    },
    {
        path: '/',
        component: PageContent,
        children: [
            // *验工计价模块
            // 验收管理详情页跳转
            {
                path: '/AcceptManageDetail',
                name: 'AcceptManageDetail',
                meta: { title: '验收管理详情' },
                component: () => import('@/views/acceptanceManagement')
            },
            {
                path: '/acceptance',
                name: 'acceptance',
                meta: { title: '验收管理详情' },
                component: () => import('@/views/acceptance')
            },
            // 验收管理详情页:综合查询
            {
                path: '/acceptanceIntegratedQuery',
                name: 'AcceptanceIntegratedQuery',
                meta: { title: '验收管理详情' },
                component: () => import('@/views/acceptance/acceptanceIntegratedQuery')
            },
            // 结算详情页跳转
            {
                path: '/settlementToExamineDetail',
                name: 'settlementToExamineDetail',
                meta: { title: '结算详情页跳转' },
                component: () => import('@/views/settlement/settlementToExamine'),
                hidden: true
            },
            // 结算送审
            {
                path: '/submitApproval',
                name: 'submitApproval',
                meta: { title: '项目结算详情' },
                component: () =>
                    import('@/views/settlement/settlementToExamine/submitApproval')
            },
            // 服务商结算调整
            {
                path: '/service',
                name: 'service',
                meta: { title: '服务商结算调整' },
                component: () => import('@/views/settlement/service'),
                hidden: true,
                beforeEnter: async (to, form, next) => {
                    console.log(to, 'to-----------')
                    const { data } = await getServConfirmParam(to.query)
                    setToken10(data.token)
                    next()
                }
            },
            // 通信类 决算页面
            {
                path: '/tFinInfoForm',
                name: 'TFinInfoForm',
                meta: { title: '决算详情' },
                component: () => import('@/views/actualBudget/communication/tFinInfoForm'),
                hidden: true
            },
            // 通信类 结算送审提交页面 && 综合查询结算送审
            {
                path: '/communicationSubmitApproval',
                name: 'CommunicationSubmitApproval',
                meta: { title: '结算送审' },
                component: () => import('@/views/actualBudget/communication/communicationSubmitApproval'),
                hidden: true
            },
            // 通信类 整体项目下单项工程页面
            {
                path: '/singleProjectMessage',
                name: 'SingleProjectMessage',
                meta: { title: '决算详情' },
                component: () => import('@/views/actualBudget/communication/singleProjectMessage'),
                hidden: true
            }
        ]
    },
    // 决算页面详情页跳转
    {
        path: '/actualBudgetDetail',
        name: 'actualBudgetDetail',
        meta: { title: '决算详情' },
        component: () => import('@/views/actualBudget/actualBudgetDetail'),
        hidden: true
    },
    // 决算送审页面详情页跳转
    {
        path: '/actualBudgetDraftDetail',
        name: 'actualBudgetDraftDetail',
        meta: { title: '决算送审详情' },
        component: () => import('@/views/actualBudget/actualBudgetDraftDetail'),
        hidden: true
    },
    // 决算:综合查询展示(通信类、信息化类)
    {
        path: '/integratedQueryActualBudget',
        name: 'integratedQueryActualBudget',
        meta: { title: '决算详情' },
        component: () => import('@/views/actualBudget/integratedQueryActualBudget'),
        hidden: true
    },
    // *验工计价模块
    //  *综合查询 - 验工计价操作
    {
        path: '/checkoutValuationOperationDetail',
        name: 'checkoutValuationOperationDetail',
        meta: { title: '验工计价' },
        component: () =>
            import(
                '@/views/checkoutValuation/checkoutValuationOperationDetail'
            ),
        hidden: true
    },
    //  *综合查询 - 查看
    {
        path: '/CheckoutValuationDetail',
        name: 'CheckoutValuationDetail',
        meta: { title: '综合查询' },
        component: () =>
            import('@/views/checkoutValuation/CheckoutValuationDetail'),
        hidden: true
    },
    // 验工计价操作 - 工程建设 - 发起验工计价
    {
        path: '/CheckoutValuationOperate',
        name: 'CheckoutValuationOperate',
        meta: { title: '发起验工计价' },
        component: () =>
            import('@/views/checkoutValuation/CheckoutValuationOperate'),
        hidden: true
    },
    // 验工计价操作 -  工程建设 - 验工计价调减
    {
        path: '/CheckoutValuationOperateAdjust',
        name: 'CheckoutValuationOperateAdjust',
        meta: { title: '验工计价调减' },
        component: () =>
            import('@/views/checkoutValuation/CheckoutValuationOperateAdjust'),
        hidden: true
    },
    //  验工计价信息-入口
    {
        path: '/detailsOfInspection',
        name: 'detailsOfInspection',
        meta: { title: '验工计价信息' },
        component: () =>
            import('@/views/checkoutValuation/detailsOfInspection'),
        hidden: true
    },
    //  项目操作-验工计价查询(验工计价,设计监理B类)
    {
        path: '/designSupervisionDetail',
        name: 'designSupervisionDetail',
        meta: { title: '验工计价查询' },
        component: () =>
            import('@/views/checkoutValuation/designSupervisionDetail'),
        hidden: true
    },

    // 验收管理 1.0临时路径
    {
        path: '/PmsServiceTabsIndex',
        name: 'PmsServiceTabsIndex',
        meta: { title: '验收管理' },
        component: () =>
            import(
                '@/views/acceptanceManagement/servicecodeDetailConfig/pmsServiceTabsIndex'
            )
    },

    // 验收管理-服务明细配置
    {
        path: '/pmsServiceTabs',
        name: 'pmsServiceTabs',
        meta: { title: '服务明细配置' },
        component: () =>
            import(
                '@/views/acceptanceManagement/servicecodeDetailConfig/ServiceTabsDetails'
            )
    },
    // todo 内部验收强校验物资总览查看列表
    {
        path: '/checkMaterials',
        name: 'checkMaterials',
        meta: { title: '验收管理' },
        component: () =>
            import(
                '@/views/acceptance/checkMaterials/checkMaterials.vue'
            )
    },
    // todo 内部验收强校验列表
    {
        path: '/interiorVerify',
        name: 'interiorVerify',
        meta: { title: '验收管理' },
        component: () =>
            import(
                '@/views/acceptance/interiorVerify.vue'
            )
    },
    //   物资管理-物资申领
    {
        path: '/getReceiveEquipInfo',
        name: 'getReceiveEquipInfo',
        meta: { title: '物资申领' },
        component: () => import('@/views/material/material'),
        hidden: true
    },
    //   物资管理-物资申领/退库
    {
        path: '/materialsApplicant',
        name: 'MaterialsApplicant',
        meta: { title: '物资申领/退库', isEdit: true },
        component: () => import('@/views/material/materialsApplicant.vue'),
        hidden: true
    },
    {
        path: '/materialsApplicantRes',
        name: 'MaterialsApplicant',
        meta: { title: '物资申领/退库', isEdit: false },
        component: () => import('@/views/material/materialsApplicant.vue'),
        hidden: true
    },
    // 附件管理-项目附件-附件补传
    {
        path: '/attachmentPass',
        name: 'AttachmentPass',
        meta: { title: '附件补传', supplementType: '1' },
        component: () =>
            import(
                '@/views/attachManagement/attachments/attachmentDetails/index.vue'
            ),
        hidden: true
    },
    // 附件管理-项目附件-附件管理
    {
        path: '/attachmentManage',
        name: 'AttachmentManage',
        meta: { title: '附件管理' },
        component: () =>
            import(
                '@/views/attachManagement/attachments/attachmentManage/index.vue'
            ),
        hidden: true
    },
    // 附件管理-项目附件-附件管理详情
    {
        path: '/attachmentDetails',
        name: 'AttachmentDetails',
        meta: { title: '附件管理详情', supplementType: '' },
        component: () =>
            import(
                '@/views/attachManagement/attachments/attachmentDetails/index.vue'
            ),
        hidden: true
    },
    // 附件管理-项目附件-附件管理详情列表
    {
        path: '/attachDetailList',
        name: 'AttachDetailList',
        meta: { title: '附件管理详情列表', supplementType: '' },
        component: () =>
            import(
                '@/views/attachManagement/attachments/attachmentDetails/attachDetailList.vue'
            ),
        hidden: true
    },
    // 附件管理-项目附件-附件信息
    {
        path: '/attachmentInfo',
        name: 'AttachmentInfo',
        meta: { title: '附件信息', supplementType: '' },
        component: () => import('@/components/attachmentInfo/indexOld.vue'),
        hidden: true
    },
    {
        path: '/attachmentInfoTodo',
        name: 'AttachmentInfoTodo',
        meta: { title: '附件信息', supplementType: '' },
        component: () => import('@/components/attachmentInfo/index.vue'),
        hidden: true
    },
    {
        path: '/attachmentFullView',
        name: 'AttachmentFullView',
        meta: { title: '附件信息', supplementType: '' },
        component: () => import('@/components/attachmentInfo/fullView.vue'),
        hidden: true
    },
    // 附件管理-综合查询-文档信息
    {
        path: '/documentInfo',
        name: 'DocumentInfo',
        meta: { title: '文档信息' },
        component: () =>
            import(
                '@/views/attachManagement/attachments/documentInfo/index.vue'
            ),
        hidden: true
    },

    {
        path: '/electronicSignaturePage',
        name: 'electronicSignaturePage',
        meta: { title: '信息化电子签章流程' },
        component: () =>
            import(
                '@/views/attachManagement/electronicSignature/index.vue'
            ),
        hidden: true
    },
    // 附件管理-电子签章-批量签章管理
    {
        path: '/bulkSigning',
        name: 'bulkSigning',
        meta: { title: '批量签章管理' },
        component: () =>
            import(
                '@/views/attachManagement/electronicSign/bulkSigning/index.vue'
            ),
        hidden: true
    },
    // 附件管理-电子签章-电子签章
    {
        path: '/electronicSignature',
        name: 'ElectronicSignature',
        meta: { title: '电子签章' },
        component: () =>
            import(
                '@/views/attachManagement/electronicSign/electronicSignature/index.vue'
            ),
        hidden: true
    },
    {
        path: '/attachSignInfoSelect',
        name: 'attachSignInfoSelect',
        meta: { title: '附件项目选择页' },
        component: () =>
            import(
                '@/views/attachManagement/electronicSign/attachSignInfoSelect/attachSignInfoSelect.vue'
            ),
        hidden: true
    },
    {
        path: '/attachSignInfo',
        name: 'attachSignInfo',
        meta: { title: '电子签章项目附件信息' },
        component: () =>
            import(
                '@/views/attachManagement/electronicSign/attachSignInfo/attachSignInfo.vue'
            ),
        hidden: true
    },
    // 附件管理-电子签章-电子签章代办
    {
        path: '/electronicSealAgent',
        name: 'ElectronicSealAgent',
        meta: { title: '电子签章待办', isDone: false },
        component: () =>
            import(
                '@/views/attachManagement/electronicSign/electronicSealAgent/index.vue'
            ),
        hidden: true
    },
    // 附件管理-电子签章-电子签章已办
    // {
    //     path: '/electronicSealDone',
    //     name: 'ElectronicSealDone',
    //     meta: { title: '电子签章已办', isDone: true },
    //     component: () =>
    //         import(
    //             '@/views/attachManagement/electronicSign/electronicSealAgent/index.vue'
    //         ),
    //     hidden: true
    // },
    // 附件管理-电子签章-电子签章配置
    {
        path: '/electronicSignConfig',
        name: 'ElectronicSignConfig',
        meta: { title: '电子签章配置' },
        component: () =>
            import(
                '@/views/attachManagement/electronicSign/electronicSignConfig/index.vue'
            ),
        hidden: true
    },
    // 附件管理-电子签章-电子签章校验配置
    {
        path: '/eleSignVerConfig',
        name: 'EleSignVerConfig',
        meta: { title: '电子签章校验配置' },
        component: () =>
            import(
                '@/views/attachManagement/electronicSign/eleSignVerConfig/index.vue'
            ),
        hidden: true
    },
    // 附件管理-电子化文档配置
    {
        path: '/electronDocCreate',
        name: 'ElectronDocCreate',
        meta: { title: '编辑电子化文档' },
        component: () =>
            import(
                '@/views/attachManagement/electronDocCreate/index.vue'
            ),
        hidden: true
    },
    // 附件管理-预览
    {
        path: '/filePreview',
        name: 'FilePreview',
        meta: { title: '预览' },
        component: () => import('@/components/business/filePreview.vue'),
        hidden: true
    },
    // *验工计价模块
    {
        path: '/inspectionValuationDetails',
        name: 'inspectionValuationDetails',
        meta: { title: '验工计价' },
        component: () =>
            import('@/views/checkoutValuation/InspectionValuationDetails'),
        hidden: true
    },
    // 验工计价模块查看
    {
        path: '/InspectionValuationDetailsView',
        name: 'InspectionValuationDetailsView',
        meta: { title: '验工计价查看' },
        component: () =>
            import('@/views/checkoutValuation/InspectionValuationDetailsView'),
        hidden: true
    },
    // 自主研发 验工计价详情查看
    {
        path: '/independentResearch',
        name: 'independentResearch',
        meta: { title: '验工计价详情' },
        component: () =>
            import('@/views/checkoutValuation/independentResearchIndex'),
        hidden: true
    },
    // 物资退库
    {
        path: '/removeMaterial',
        name: 'removeMaterial',
        meta: { title: '物资退库' },
        component: () => import('@/views/material/removeMaterial'),
        hidden: true
    },
    // 实施阶段物资申领
    {
        path: '/getReceiveInfo',
        name: 'getReceiveInfo',
        meta: { title: '物资申领' },
        component: () => import('@/views/material/getReceiveInfo'),
        hidden: true
    },
    // 物资申领详情
    {
        path: '/materialInfo',
        name: 'materialInfo',
        meta: { title: '物资申领详情' },
        component: () => import('@/views/material/materialinfo'),
        hidden: true
    },
    // 物资申领详情
    {
        path: '/outPutMaterialInfo',
        name: 'outPutMaterialInfo',
        meta: { title: '物资申领详情' },
        component: () => import('@/views/material/materialOutPut'),
        hidden: true
    },
    // 物资申领详情aaa
    {
        path: '/materialsApplicationAll',
        name: 'MaterialsApplicationAll',
        meta: { title: '物资申领详情' },
        component: () => import('@/views/material/components/materialsApplicationAll.vue'),
        hidden: true
    },
    // 附件管理-档案归档
    {
        path: '/archiving',
        name: 'Archiving',
        meta: { title: '档案归档' },
        component: () =>
            import(
                '@/views/attachManagement/archiving/index.vue'
            ),
        hidden: true
    },
    // 结决算管理-决算导出
    {
        path: '/actualBudgetExport',
        name: 'ActualBudgetExport',
        meta: { title: '决算导出' },
        component: () =>
            import(
                '@/views/SettlementAndFinalAccounts/SettlementAndFinalAccountsExport/actualBudgetExport.vue'
            ),
        hidden: true
    },
    // 结决算管理-结算导出
    {
        path: '/settlementExport',
        name: 'SettlementExport',
        meta: { title: '结算导出' },
        component: () =>
            import(
                '@/views/SettlementAndFinalAccounts/SettlementAndFinalAccountsExport/SettlementExport.vue'
            ),
        hidden: true
    },
    // 结决管理-项目授权迁移
    {
        path: '/projectAuthorizationMigration',
        name: 'ProjectAuthorizationMigration',
        meta: { title: '项目授权迁移' },
        component: () =>
            import(
                '@/views/SettlementAndFinalAccounts/projectAuthorizationMigration/index.vue'
            ),
        hidden: true
    },
    //   结算管理-页面重构
    {
        path: '/settlementManagement',
        name: 'SettlementManagement',
        meta: { title: '结算确认待办' },
        component: () =>
            import(
                '@/views/balance/index.vue'
            ),
        hidden: true
    },
    // 结算页面全屏新开页面
    {
        path: '/purchaseOrder',
        name: 'PurchaseOrder',
        meta: { title: '结算确认待办' },
        component: () =>
            import(
                '@/views/balance/purchaseOrder/PurchaseOrder.vue'
            ),
        hidden: true
    },
    //   结算管理-服务商确认代办页面
    {
        path: '/suppierManagement',
        name: 'SuppierManagement',
        meta: { title: '供应商确认待办' },
        component: () =>
            import(
                '@/views/balance/suppierconfirm/suppierManagement.vue'
            ),
        hidden: true
    },
    // 结算管理-服务商确认代办-全屏新开页面
    {
        path: '/suppierConfirm',
        name: 'SuppierConfirm',
        meta: { title: '供应商确认待办' },
        component: () =>
            import(
                '@/views/balance/suppierconfirm/suppierConfirm.vue'
            ),
        hidden: true
    },
    // 业务派单
    {
        path: '/businessSendorders',
        name: 'BusinessSendorders',
        meta: { title: '业务派单' },
        component: () =>
            import(
                '@/views/businessOperation/businessSendorders.vue'
            ),
        hidden: true
    },
    // 业务接单 - 我的待办
    {
        path: '/sendOrdersBacklog',
        name: 'SendOrdersBacklog',
        meta: { title: '业务接单' },
        component: () =>
            import(
                '@/views/businessOperation/sendOrdersBacklog.vue'
            ),
        hidden: true
    },
    // 验收管理 - 物资服务绑定
    {
        path: '/materialServiceBind',
        name: 'MaterialServiceBind',
        meta: { title: '物资服务绑定' },
        component: () =>
            import('@/views/acceptanceManagement/materialServiceBind/index.vue'),
        hidden: true
    },
    // 物资申领详情
    {
        path: '/materialReconfigurationInfo',
        name: 'MaterialReconfigurationInfo',
        meta: { title: '物资申领详情' },
        component: () => import('@/views/materialReconfiguration/materialinfo'),
        hidden: true
    },
    // 研发查看验工计价页面
    {
        path: '/researchInspectionInfo',
        name: 'ResearchInfo',
        meta: { title: '物资申领详情' },
        component: () => import('@/views/checkoutValuation/inspectPage'),
        hidden: true
    },
    // 业务派单综合查询页面
    {
        path: '/businessSendList',
        name: 'BusinessSendList',
        meta: { title: '派单查询' },
        component: () =>
            import(
                '@/views/businessOperation/pages/index.vue'
            ),
        hidden: true
    },
    // 可退至虚拟库物料分类
    {
        path: '/materialClassification',
        name: 'MaterialClassification',
        meta: { title: '可退至虚拟库物料分类' },
        component: () =>
            import(
                '@/views/material/components/materialClassification.vue'
            ),
        hidden: true
    },
    // 选择绑定签码数据
    {
        path: '/resourceCodeAndLabelOne',
        name: 'ResourceCodeAndLabelOne',
        meta: { title: '选择绑定签码数据' },
        component: () =>
            import(
                '@/views/acceptanceManagement/materialServiceBind/components/resourceCodeAndLabelOne.vue'
            ),
        hidden: true
    },
    // 换签审批页
    {
        path: '/changeLabel',
        name: 'ChangeLabel',
        meta: { title: '换签审批' },
        component: () =>
            import(
                '@/views/material/changeLabel/index.vue'
            ),
        hidden: true
    },
    //决算送审列表
    {
        path: '/checkFinalAccounts',
        name: 'CheckFinalAccounts',
        meta: { title: '决算送审详情' },
        component: () =>
            import(
                '@/views/finalAccounts/index.vue'
            ),
        hidden: true
    },
    {
        path: '/handleFinalAccounts',
        name: 'HandleFinalAccounts',
        meta: { title: '决算送审' },
        component: () =>
            import(
                '@/views/finalAccounts/finalAccountsSendReview/index.vue'
            ),
        hidden: true
    },
    {
        path: '/searchFinalAccounts',
        name: 'SearchFinalAccounts',
        meta: { title: '决算送审查询' },
        component: () =>
            import(
                '@/views/finalAccounts/finalAccountsDetails/index.vue'
            ),
        hidden: true
    },
    {
        path: '/handleSpecialCorrection',
        name: 'HandleSpecialCorrection',
        meta: { title: '特别修正详情' },
        component: () =>
            import(
                '@/views/speciaCorrection/index.vue'
            ),
        hidden: true
    },
    {
        path: '/specialConfiguration',
        name: 'SpecialConfiguration',
        meta: { title: '特别修正审批配置' },
        component: () =>
            import(
                '@/views/speciaCorrection/configuration/index.vue'
            ),
        hidden: true
    },
    {
        path: '/specialConfigurationListInfo',
        name: 'SpecialConfigurationListInfo',
        meta: { title: '特别修正列表详情' },
        component: () =>
            import(
                '@/views/speciaCorrection/searchList/index.vue'
            ),
        hidden: true
    },
    {
        path: '/specialConfigurationSearchInfo',
        name: 'SpecialConfigurationSearchInfo',
        meta: { title: '特别修正查询详情' },
        component: () =>
            import(
                '@/views/speciaCorrection/searchInfo/index.vue'
            ),
        hidden: true
    },
    {
        path: '/specialCorrectionSendReview',
        name: 'SpecialCorrectionSendReview',
        meta: { title: '特别修正结算送审' },
        component: () =>
            import(
                '@/views/speciaCorrection/specialCorrectionSendReview/index.vue'
            ),
        hidden: true
    },
    {
        path: '/progressWarnExport',
        name: 'progressWarnExport',
        meta: { title: '项目进度预警' },
        component: () =>
            import(
                '@/views/progressWarn/index.vue'
            ),
        hidden: true
    },
    {
        path: '/handleDeclineBank',
        name: 'HandleDeclineBank',
        meta: { title: '物资审减退库详情' },
        component: () =>
            import(
                '@/views/declinebank/index.vue'
            ),
        hidden: true
    },
    {
        path: '/declineBankList',
        name: 'DeclineBankList',
        meta: { title: '审减退库列表详情' },
        component: () =>
            import(
                '@/views/declinebank/searchList/index.vue'
            ),
        hidden: true
    },
    {
        path: '/declineBankSearchInfo',
        name: 'DeclineBankSearchInfo',
        meta: { title: '审减退库查询详情' },
        component: () =>
            import(
                '@/views/declinebank/searchInfo/index.vue'
            ),
        hidden: true
    },
    {
        path: '/adjustProject',
        name: 'AdjustProject',
        meta: { title: '跨项目调整' },
        component: () =>
            import(
                '@/views/adjustProject/index.vue'
            ),
        hidden: true
    },
    {
        path: '/skipreceiptInfo',
        name: 'SkipreceiptInfo',
        meta: { title: '项目接维详情' },
        component: () =>
            import(
                '@/views/acceptance/receipt/index.vue'
            ),
        hidden: true
    },
    // 预警督办-红黄灯预警提醒
    {
        path: '/redYellowLightWarn',
        name: 'RedYellowLightWarn',
        meta: { title: '红黄灯预警提醒' },
        component: () =>
            import(
                '@/views/warningReminder/redYellowLightWarn/index.vue'
            ),
        hidden: true
    },
    { path: '/403', component: () => import('@/views/403.vue'), hidden: true },
    { path: '*', redirect: '/404', hidden: true }
]

// 路由创建
lazyRouter.add(
    '/base',
    'Base',
    '/base/article',
    { title: '', icon: 'dashboard', affix: true },
    Layout,
    routerArr,
    { require: true }
)
const routers = getRoutes(constantRoutes.concat(lazyRouter.routes))

const createRouter = () =>
    new Router({
        mode: 'history', // require service support
        scrollBehavior: () => ({ y: 0 }),
        base: '/pms-application/',
        routes: routers
    })

const router = createRouter()

router.beforeEach(async (to, from, next) => {
    const { workItemId, type } = to.query;
    const getToken = sessionStorage.getItem('china-tower-token-pms20')
    const spacltTag = ['electronicSignaturePage','ElectronicSealAgent'].includes(to.name) && type === 'todo'
    const getPage = ['SendOrdersBacklog','BusinessSendorders','InspectionValuationDetailsView','ChangeLabel','AdjustProject','HandleSpecialCorrection','HandleDeclineBank','SuppierManagement', 'PurchaseOrder', 'SettlementManagement', 'AcceptManageDetail', 'acceptance', 'TFinInfoForm', 'actualBudgetDetail', 'actualBudgetDraftDetail']
    // 代办 已办
    if (workItemId && (spacltTag || getPage.includes(to.name))) {
        const res = await checkToken()
        // 不存在token 或者校验失败，跳转403页面
        if (!getToken || +res.code !== 200) {
            return next('/403')
        }
        // 鉴权接口调用 
        const result = await checkResourceEnter({ workItemId: workItemId })
        if (+result.code === 40301) {
            next('/403')
        } else {
            next()
        }
    }
    next()
})
export function resetRouter() {
    const newRouter = createRouter()
    router.matcher = newRouter.matcher // reset router
}

export default router

